home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume6 / yahp2ps / part02 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  27.9 KB

  1. Path: xanth!nic.MR.NET!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!allbery
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Newsgroups: comp.sources.misc
  4. Subject: v06i004: HPGL to PostScript converter (Part 2 of 6)
  5. Message-ID: <46900@uunet.UU.NET>
  6. Date: 21 Jan 89 20:29:16 GMT
  7. Sender: allbery@uunet.UU.NET
  8. Reply-To: federico@actisb.UUCP (Federico Heinz)
  9. Organization: ACTIS in Berlin GmbH, W. Germany
  10. Lines: 1101
  11. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  12.  
  13. Posting-number: Volume 6, Issue 4
  14. Submitted-by: federico@actisb.UUCP (Federico Heinz)
  15. Archive-name: yahp2ps/part02
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 2 (of 6)."
  24. # Contents:  defs.h dispatch.c global.c io.h math.c mchinery.h tick.c
  25. # Wrapped by federico@actisb on Wed Jan  4 13:34:45 1989
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'defs.h' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'defs.h'\"
  29. else
  30. echo shar: Extracting \"'defs.h'\" \(3976 characters\)
  31. sed "s/^X//" >'defs.h' <<'END_OF_FILE'
  32. X/*
  33. X        HPGL to PostScript converter
  34. X   Copyright (C) 1988 (and following) Federico Heinz
  35. X
  36. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  37. XWARRANTY.  No author or distributor accepts responsibility to anyone
  38. Xfor the consequences of using it or for whether it serves any
  39. Xparticular purpose or works at all, unless he says so in writing.
  40. XRefer to the Free Software Foundation's General Public License for full details.
  41. X
  42. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  43. Xbut only under the conditions described in the GNU General Public
  44. XLicense.  A copy of this license is supposed to have been given to you
  45. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  46. Xshould be in a file named COPYING.  Among other things, the copyright
  47. Xnotice and this notice must be preserved on all copies.
  48. X
  49. XIn other words, go ahead and share yahp2ps, but don't try to stop
  50. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  51. X
  52. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  53. Xit is only released under the same conditions.
  54. X
  55. X    For bug reports, wishes, etc. send e-mail to
  56. X
  57. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  58. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  59. X
  60. X    For Physical mail:
  61. X
  62. X    Federico Heinz
  63. X    Beusselstr. 21
  64. X    1000 Berlin 21
  65. X
  66. X    Tel. (+49 30) 396 77 92
  67. X
  68. X*/
  69. X/***************************************************************************
  70. X
  71. X        Yet Another HPGL to PostScript Converter.
  72. X
  73. X
  74. X***************************************************************************/
  75. X
  76. X
  77. X/**************************************************************************
  78. X
  79. X    System-dependent constants.
  80. X
  81. X**************************************************************************/
  82. X
  83. X#define    DEFAULT_PRELUDE "/usr/lib/yahp2ps.pre" /* default prelude file */
  84. X
  85. X
  86. X/**************************************************************************
  87. X
  88. X   Define the Number data type. It represents the Scaled Decimal
  89. X   format of HPGL. In order to get a Number out of a normal integer,
  90. X   multiply it by the constant One.
  91. X
  92. X**************************************************************************/
  93. X
  94. X
  95. X
  96. X#define Number  long int
  97. X
  98. X#define IntPlaces 5
  99. X#define DecPlaces 4
  100. X
  101. X
  102. X/* A CoordinatePair contains an X and a Y component */
  103. X
  104. X#define X       0
  105. X#define Y       1
  106. X
  107. Xtypedef Number  CoordinatePair[2];
  108. X
  109. X
  110. Xextern Number RelativeCharWidth;   /* Width of each char          */
  111. Xextern Number RelativeCharHeigth;  /* Heigth of each char         */
  112. Xextern Number CharacterDirection;  /* Text writing angle          */
  113. Xextern Number CharacterSlant;      /* Textual slant angle         */
  114. X
  115. Xextern Number TN; /* Temporary storage for avoiding side effects
  116. X                        in Number-handling macros */
  117. X
  118. X
  119. X/* Some constants in our numbering system */
  120. X
  121. X#define One             10000L
  122. X#define Zero            0L
  123. X
  124. X/* Divide a Number by another (a Number may be divided by an integer the
  125. X   usual way) */
  126. X
  127. X
  128. Xextern Number divNum();
  129. X
  130. X
  131. X/* Multiply a Number by another (again, multiplication by an integer is
  132. X   as usual) */
  133. X
  134. X
  135. Xextern Number mulNum();
  136. X
  137. X
  138. X/* Truncate a number according to the HPGL rules */
  139. X
  140. X#define trunc(x)        (((TN = (x)) % One) ? \
  141. X                            ((TN = (TN/One) * One) < 0 ? \
  142. X                                (TN - One) : TN) : TN)
  143. X
  144. X
  145. X/***************************************************************************
  146. X
  147. X   Define the Boolean data type.
  148. X
  149. X***************************************************************************/
  150. X
  151. X
  152. X#define Boolean int
  153. X
  154. X#define True  1
  155. X#define False 0
  156. X
  157. X
  158. X
  159. X
  160. X
  161. X
  162. X/* Special character predicates */
  163. X
  164. X#define isSeparator(x)  (((x) == ',') || ((x) == ' '))
  165. X#define isTerminator(x) (((x) == ';') || ((x) == '\n'))
  166. X
  167. X
  168. X
  169. X/***************************************************************************
  170. X
  171. X  Error handling functions.
  172. X
  173. X***************************************************************************/
  174. X
  175. Xextern void warning();
  176. Xextern void error();
  177. X
  178. X
  179. X
  180. X
  181. END_OF_FILE
  182. if test 3976 -ne `wc -c <'defs.h'`; then
  183.     echo shar: \"'defs.h'\" unpacked with wrong size!
  184. fi
  185. # end of 'defs.h'
  186. fi
  187. if test -f 'dispatch.c' -a "${1}" != "-c" ; then 
  188.   echo shar: Will not clobber existing file \"'dispatch.c'\"
  189. else
  190. echo shar: Extracting \"'dispatch.c'\" \(3258 characters\)
  191. sed "s/^X//" >'dispatch.c' <<'END_OF_FILE'
  192. X/*
  193. X        HPGL to PostScript converter
  194. X   Copyright (C) 1988 (and following) Federico Heinz
  195. X
  196. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  197. XWARRANTY.  No author or distributor accepts responsibility to anyone
  198. Xfor the consequences of using it or for whether it serves any
  199. Xparticular purpose or works at all, unless he says so in writing.
  200. XRefer to the Free Software Foundation's General Public License for full details.
  201. X
  202. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  203. Xbut only under the conditions described in the GNU General Public
  204. XLicense.  A copy of this license is supposed to have been given to you
  205. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  206. Xshould be in a file named COPYING.  Among other things, the copyright
  207. Xnotice and this notice must be preserved on all copies.
  208. X
  209. XIn other words, go ahead and share yahp2ps, but don't try to stop
  210. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  211. X
  212. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  213. Xit is only released under the same conditions.
  214. X
  215. X    For bug reports, wishes, etc. send e-mail to
  216. X
  217. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  218. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  219. X
  220. X    For Physical mail:
  221. X
  222. X    Federico Heinz
  223. X    Beusselstr. 21
  224. X    1000 Berlin 21
  225. X
  226. X    Tel. (+49 30) 396 77 92
  227. X
  228. X*/
  229. X/**************************************************************************
  230. X
  231. X  Main loop. Here's where the decoding takes place.
  232. X
  233. X**************************************************************************/
  234. X
  235. X
  236. X
  237. X#include "defs.h"
  238. X#include "dispatch.h"
  239. X#include "mchinery.h"
  240. X#include "io.h"
  241. X
  242. X
  243. X/*
  244. X
  245. X  A command that does not make sense in a PostScript environment.
  246. X
  247. X*/
  248. X
  249. XCommandImplementation notImplemented()
  250. X
  251. X{ warning("Useless command skipped.");
  252. X  endCommand();
  253. X}
  254. X
  255. X
  256. X
  257. X/*
  258. X
  259. X  A command that requires Plotter-Computer interaction in real time.
  260. X
  261. X*/
  262. X
  263. XCommandImplementation interactive()
  264. X
  265. X{ error("Cannot handle commands requiring Plotter-Computer interaction.");
  266. X}
  267. X
  268. X
  269. X
  270. Xtypedef CommandImplementation (*CommandPointer)();
  271. X
  272. X
  273. Xstatic CommandPointer DoCommand[] =
  274. X  {     notImplemented,
  275. X        interactive,
  276. X        arcAbsolute,
  277. X        arcRelative,
  278. X        setAlternateChar,
  279. X        circle,
  280. X        characterPlot,
  281. X        setStandardChar,
  282. X        setDefaults,
  283. X        setAbsoluteDirection,
  284. X        setRelativeDirection,
  285. X        setLabelTerminator,
  286. X        rectangleAbsolute,
  287. X        rectangleRelative,
  288. X        wedge,
  289. X        setFillType,
  290. X        initialize,
  291. X        inputP1P2,
  292. X        inputWindow,
  293. X        putASCIILabel,
  294. X        setLineType,
  295. X        setAbsolutePlot,
  296. X        penDown,
  297. X        setRelativePlot,
  298. X        setPaperSize,
  299. X        penUp,
  300. X        shadeRectAbsolute,
  301. X        rotateCoordSys,
  302. X        shadeRectRelative,
  303. X        selectAlternate,
  304. X        setScale,
  305. X        setAbsoluteCharSize,
  306. X        setAbsoluteCharSlant,
  307. X        setSymbolMode,
  308. X        selectPen,
  309. X        setRelativeCharSize,
  310. X        selectStandard,
  311. X        setTickLength,
  312. X        userChar,
  313. X        shadeWedge,
  314. X        xTick,
  315. X        yTick,
  316. X    penThickness
  317. X  };
  318. X
  319. X
  320. X
  321. X/*
  322. X
  323. X  Process a whole HPGL document.
  324. X
  325. X*/
  326. X
  327. Xvoid dispatch()
  328. X
  329. X{   skipSeparator();
  330. X   while (LookAhead != EOF) (*DoCommand[getCommand()])();
  331. X}
  332. X
  333. X
  334. END_OF_FILE
  335. if test 3258 -ne `wc -c <'dispatch.c'`; then
  336.     echo shar: \"'dispatch.c'\" unpacked with wrong size!
  337. fi
  338. # end of 'dispatch.c'
  339. fi
  340. if test -f 'global.c' -a "${1}" != "-c" ; then 
  341.   echo shar: Will not clobber existing file \"'global.c'\"
  342. else
  343. echo shar: Extracting \"'global.c'\" \(4058 characters\)
  344. sed "s/^X//" >'global.c' <<'END_OF_FILE'
  345. X/*
  346. X        HPGL to PostScript converter
  347. X   Copyright (C) 1988 (and following) Federico Heinz
  348. X
  349. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  350. XWARRANTY.  No author or distributor accepts responsibility to anyone
  351. Xfor the consequences of using it or for whether it serves any
  352. Xparticular purpose or works at all, unless he says so in writing.
  353. XRefer to the Free Software Foundation's General Public License for full details.
  354. X
  355. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  356. Xbut only under the conditions described in the GNU General Public
  357. XLicense.  A copy of this license is supposed to have been given to you
  358. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  359. Xshould be in a file named COPYING.  Among other things, the copyright
  360. Xnotice and this notice must be preserved on all copies.
  361. X
  362. XIn other words, go ahead and share yahp2ps, but don't try to stop
  363. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  364. X
  365. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  366. Xit is only released under the same conditions.
  367. X
  368. X    For bug reports, wishes, etc. send e-mail to
  369. X
  370. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  371. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  372. X
  373. X    For Physical mail:
  374. X
  375. X    Federico Heinz
  376. X    Beusselstr. 21
  377. X    1000 Berlin 21
  378. X
  379. X    Tel. (+49 30) 396 77 92
  380. X
  381. X*/
  382. X/************************************************************************
  383. X
  384. X   Commands affecting the virtual plotter's global state.
  385. X
  386. X************************************************************************/
  387. X
  388. X#include "defs.h"
  389. X#include "dispatch.h"
  390. X#include "io.h"
  391. X#include "mchinery.h"
  392. X#include "penctrl.h"
  393. X#include "circle.h"
  394. X#include "shade.h"
  395. X#include "tick.h"
  396. X#include "global.h"
  397. X#include "char.h"
  398. X
  399. X
  400. X/*
  401. X
  402. X  Set the default values for the parameters controlled by this module.
  403. X
  404. X*/
  405. X
  406. Xvoid globalInit()
  407. X
  408. X{ resetWindow();
  409. X  turnScalingOff();
  410. X}
  411. X
  412. X
  413. X/*
  414. X
  415. X  Restore default values of all modules.
  416. X
  417. X*/
  418. X
  419. Xvoid restoreDefaults()
  420. X
  421. X{ globalInit();
  422. X  basicInit();
  423. X  shadeInit();
  424. X  tickInit();
  425. X  charInit();
  426. X}
  427. X
  428. X
  429. X/*
  430. X
  431. X  Reset default values for plotter opeartion.
  432. X
  433. X*/
  434. X
  435. XCommandImplementation setDefaults()
  436. X
  437. X{ restoreDefaults();
  438. X  endCommand();
  439. X}
  440. X
  441. X
  442. X/*
  443. X
  444. X  Restart plotter.
  445. X
  446. X*/
  447. X
  448. XCommandImplementation initialize()
  449. X
  450. X{ penctrlInit();
  451. X  restoreDefaults();
  452. X  endCommand();
  453. X}
  454. X
  455. X
  456. XCommandImplementation inputP1P2()
  457. X
  458. X{ CoordinatePair newPlotterP1, newPlotterP2;
  459. X
  460. X  if (isTerminator(LookAhead))
  461. X    resetP1P2();
  462. X  else if (getCoordinatePair(newPlotterP1))
  463. X  { if (isTerminator(LookAhead) || !getCoordinatePair(newPlotterP2))
  464. X    { newPlotterP2[X] += newPlotterP1[X] - PlotterP1[X];
  465. X      newPlotterP2[Y] += newPlotterP1[Y] - PlotterP1[Y];
  466. X    }
  467. X    changeP1P2(newPlotterP1, newPlotterP2);
  468. X  }
  469. X  endCommand();
  470. X}
  471. X
  472. X
  473. X
  474. X/*
  475. X
  476. X  Set the clipping rectangle.
  477. X
  478. X*/
  479. X
  480. XCommandImplementation inputWindow()
  481. X
  482. X{ CoordinatePair corner1, corner2;
  483. X
  484. X  if (isTerminator(LookAhead) || !getCoordinatePair(corner1) ||
  485. X      !getCoordinatePair(corner2))
  486. X    resetWindow();
  487. X  else 
  488. X  { corner1[X] = trunc(corner1[X]);
  489. X    corner1[Y] = trunc(corner1[Y]);
  490. X    corner2[X] = trunc(corner2[X]);
  491. X    corner2[Y] = trunc(corner2[Y]);
  492. X    setWindow(corner1,corner2);
  493. X  }
  494. X  endCommand();
  495. X}
  496. X
  497. X
  498. X
  499. XCommandImplementation setPaperSize()
  500. X
  501. X{ Number temp;
  502. X
  503. X  if (getInteger(&temp))
  504. X    if (temp < PaperSizeLimit)
  505. X      warning("Sorry, only DIN A4 paper currently supported.");
  506. X}
  507. X
  508. X
  509. X
  510. X/*
  511. X
  512. X  Rotate the coordinate system.
  513. X
  514. X*/
  515. X
  516. XCommandImplementation rotateCoordSys()
  517. X
  518. X{ Number angle;
  519. X
  520. X  if (isTerminator(LookAhead))
  521. X    unRotate();
  522. X  else if (getNumber(&angle))
  523. X    if (angle == Zero)
  524. X      unRotate();
  525. X    else if (angle == OneSquare)
  526. X      rotate();
  527. X    else
  528. X      warning("Erroneous rotation angle.");
  529. X  endCommand();
  530. X}
  531. X
  532. X
  533. X
  534. XCommandImplementation setScale()
  535. X
  536. X{ CoordinatePair newUserP1, newUserP2;
  537. X
  538. X  if (isTerminator(LookAhead))
  539. X    turnScalingOff();
  540. X  else if (getNumber(&newUserP1[X]) && getNumber(&newUserP2[X]) &&
  541. X           getNumber(&newUserP1[Y]) && getNumber(&newUserP2[Y]))
  542. X    turnScalingOn(newUserP1, newUserP2);
  543. X  endCommand();
  544. X}
  545. X
  546. X
  547. X
  548. X
  549. END_OF_FILE
  550. if test 4058 -ne `wc -c <'global.c'`; then
  551.     echo shar: \"'global.c'\" unpacked with wrong size!
  552. fi
  553. # end of 'global.c'
  554. fi
  555. if test -f 'io.h' -a "${1}" != "-c" ; then 
  556.   echo shar: Will not clobber existing file \"'io.h'\"
  557. else
  558. echo shar: Extracting \"'io.h'\" \(2983 characters\)
  559. sed "s/^X//" >'io.h' <<'END_OF_FILE'
  560. X/*
  561. X        HPGL to PostScript converter
  562. X   Copyright (C) 1988 (and following) Federico Heinz
  563. X
  564. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  565. XWARRANTY.  No author or distributor accepts responsibility to anyone
  566. Xfor the consequences of using it or for whether it serves any
  567. Xparticular purpose or works at all, unless he says so in writing.
  568. XRefer to the Free Software Foundation's General Public License for full details.
  569. X
  570. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  571. Xbut only under the conditions described in the GNU General Public
  572. XLicense.  A copy of this license is supposed to have been given to you
  573. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  574. Xshould be in a file named COPYING.  Among other things, the copyright
  575. Xnotice and this notice must be preserved on all copies.
  576. X
  577. XIn other words, go ahead and share yahp2ps, but don't try to stop
  578. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  579. X
  580. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  581. Xit is only released under the same conditions.
  582. X
  583. X    For bug reports, wishes, etc. send e-mail to
  584. X
  585. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  586. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  587. X
  588. X    For Physical mail:
  589. X
  590. X    Federico Heinz
  591. X    Beusselstr. 21
  592. X    1000 Berlin 21
  593. X
  594. X    Tel. (+49 30) 396 77 92
  595. X
  596. X*/
  597. X/**************************************************************************
  598. X
  599. X  Input/Output definitions.
  600. X
  601. X***************************************************************************/
  602. X
  603. X#ifndef EOF
  604. X
  605. X#define EOF     (-1)
  606. X
  607. X#endif
  608. X
  609. X/* Check whether char can be beginning of a number */
  610. X
  611. X#define isNumeric(x) (isdigit(x) || ((x) == '+') || \
  612. X            ((x) == '-') || ((x) == '.'))
  613. X
  614. X/* One-char lookahead buffer */
  615. X
  616. Xextern int LookAhead;
  617. X
  618. X
  619. Xextern void    skipSeparator(); /* Skip over one or more HPGL separators   */
  620. Xextern void    skipTerminator();/* Skip over one or more HPGL terminators  */
  621. Xextern int     getChar();       /* Get the next char from the input stream */
  622. Xextern void    putChar();    /* Put a char to the output stream         */
  623. Xextern Boolean getNumber();     /* Get a Number from the input stream      */
  624. Xextern Boolean ASCIIToNumber(); /* Get a Number from an alpha string       */
  625. Xextern Boolean getInteger();    /* Get an Integer from the in stream       */
  626. X                                /* Get a CoordinatePair from the in stream */
  627. Xextern Boolean getCoordinatePair();
  628. Xextern void    endCommand();    /* Check for excess parameters & skip Term.*/
  629. Xextern void    writeNumber();   /* Put a Number to the output stream       */
  630. X                                /* Put a CoordinatePair to the out stream  */
  631. Xextern void    writeCoordinatePair();
  632. Xextern void    writeString();   /* Put a string to the output stream       */
  633. X
  634. Xextern Boolean setInput();      /* Reassign the input stream              */
  635. Xextern Boolean setOutput();     /* Reassign the output stream             */
  636. X
  637. END_OF_FILE
  638. if test 2983 -ne `wc -c <'io.h'`; then
  639.     echo shar: \"'io.h'\" unpacked with wrong size!
  640. fi
  641. # end of 'io.h'
  642. fi
  643. if test -f 'math.c' -a "${1}" != "-c" ; then 
  644.   echo shar: Will not clobber existing file \"'math.c'\"
  645. else
  646. echo shar: Extracting \"'math.c'\" \(3532 characters\)
  647. sed "s/^X//" >'math.c' <<'END_OF_FILE'
  648. X/*
  649. X        HPGL to PostScript converter
  650. X   Copyright (C) 1988 (and following) Federico Heinz
  651. X
  652. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  653. XWARRANTY.  No author or distributor accepts responsibility to anyone
  654. Xfor the consequences of using it or for whether it serves any
  655. Xparticular purpose or works at all, unless he says so in writing.
  656. XRefer to the Free Software Foundation's General Public License for full details.
  657. X
  658. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  659. Xbut only under the conditions described in the GNU General Public
  660. XLicense.  A copy of this license is supposed to have been given to you
  661. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  662. Xshould be in a file named COPYING.  Among other things, the copyright
  663. Xnotice and this notice must be preserved on all copies.
  664. X
  665. XIn other words, go ahead and share yahp2ps, but don't try to stop
  666. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  667. X
  668. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  669. Xit is only released under the same conditions.
  670. X
  671. X    For bug reports, wishes, etc. send e-mail to
  672. X
  673. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  674. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  675. X
  676. X    For Physical mail:
  677. X
  678. X    Federico Heinz
  679. X    Beusselstr. 21
  680. X    1000 Berlin 21
  681. X
  682. X    Tel. (+49 30) 396 77 92
  683. X
  684. X*/
  685. X/**********************************************************************
  686. X
  687. X   Number multiplication & division.
  688. X
  689. X**********************************************************************/
  690. X
  691. X
  692. X#include "defs.h"
  693. X
  694. X
  695. X/*
  696. X
  697. X  Make both operands positive, return True if result will be negative.
  698. X
  699. X*/
  700. X
  701. Xstatic Boolean makePositive(a, b)
  702. X
  703. XNumber *a, *b;
  704. X
  705. X{ Boolean negative;
  706. X
  707. X  if (negative = (*a < Zero)) *a = -*a;
  708. X  if (*b < Zero)
  709. X  { *b = -*b;
  710. X    negative = !negative;
  711. X  }
  712. X  return(negative);
  713. X}
  714. X
  715. X
  716. X
  717. X/*
  718. X
  719. X  Return a * b.
  720. X
  721. X  Algorithm: multiply (m 10^4 + n) (p 10^4 + q) , then divide by 10^4
  722. X  to realign the decimal point.
  723. X
  724. X  [ m 10^4 p 10^4 + m 10^4 q + n p 10^4 + n q ] / 10^-4 =
  725. X  m p 10^4 + m q + n p + n q 10-4
  726. X  
  727. X  Since I keep 4 decimal digit precision, only digits overflowing
  728. X  9999 in the term (n q 10^-4) are taken into account.
  729. X
  730. X*/
  731. X
  732. XNumber mulNum(a, b)
  733. X
  734. XNumber a, b;
  735. X
  736. X{ Number n, p, q;
  737. X  Boolean negative;
  738. X  Number result, carry;
  739. X
  740. X  negative = makePositive(&a, &b);  
  741. X  n = a % One;
  742. X  p = b / One; q = b % One;
  743. X  result = (a / One) * (p * One + q) + n * p + ((n * q) / One);
  744. X  return(negative ? -result : result);
  745. X}
  746. X
  747. X
  748. X
  749. X/*
  750. X
  751. X  Return a / b.
  752. X
  753. X  Algorithm: In case b has no dec places, then simply divide a by (b/10^4).
  754. X    Otherwise, a must be multiplyed by 10^4 before the division in order
  755. X    to get the decimals places right. But that can lead to overflow.
  756. X    So let a = m 10^4 + n
  757. X    
  758. X  [(m 10^4 + n) 10^4 ] / b = (m 10^8) / b + (n 10^4) / b
  759. X  
  760. X  [(n 10^4) / b] is easily computed. Now let (m 10^4) = (q b + r).
  761. X  Then,
  762. X  
  763. X  (m 10^8) / b = [(q b + r) 10^4] / b = [(q b 10^4) / b] + [(r 10^4) / b] =
  764. X  (q 10^4) + [(r 10^4) / b]
  765. X  
  766. X  Where both terms are easily computed. The complete formula is then
  767. X  
  768. X  a / b = q 10^4 + (r 10^4) / b + (n 10^4) / b =
  769. X          q 10^4 + [(r + n) 10^4] / b
  770. X
  771. X  [ Phew! ]
  772. X
  773. X*/
  774. X
  775. XNumber divNum(a, b)
  776. X
  777. XNumber a, b;
  778. X
  779. X{ Number q, m, result;
  780. X  Boolean negative;
  781. X
  782. X  if (!(b % One))        /* Easy case: no decimals in divisor */
  783. X    return(a / (b / One));
  784. X  negative = makePositive(&a, &b);
  785. X  m = trunc(a);
  786. X  q = m / b;
  787. X  result = q * One + (((m - q * b) + (a % One)) * One) / b;
  788. X  return(negative ? -result : result);
  789. X}
  790. END_OF_FILE
  791. if test 3532 -ne `wc -c <'math.c'`; then
  792.     echo shar: \"'math.c'\" unpacked with wrong size!
  793. fi
  794. # end of 'math.c'
  795. fi
  796. if test -f 'mchinery.h' -a "${1}" != "-c" ; then 
  797.   echo shar: Will not clobber existing file \"'mchinery.h'\"
  798. else
  799. echo shar: Extracting \"'mchinery.h'\" \(2712 characters\)
  800. sed "s/^X//" >'mchinery.h' <<'END_OF_FILE'
  801. X/*
  802. X        HPGL to PostScript converter
  803. X   Copyright (C) 1988 (and following) Federico Heinz
  804. X
  805. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  806. XWARRANTY.  No author or distributor accepts responsibility to anyone
  807. Xfor the consequences of using it or for whether it serves any
  808. Xparticular purpose or works at all, unless he says so in writing.
  809. XRefer to the Free Software Foundation's General Public License for full details.
  810. X
  811. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  812. Xbut only under the conditions described in the GNU General Public
  813. XLicense.  A copy of this license is supposed to have been given to you
  814. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  815. Xshould be in a file named COPYING.  Among other things, the copyright
  816. Xnotice and this notice must be preserved on all copies.
  817. X
  818. XIn other words, go ahead and share yahp2ps, but don't try to stop
  819. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  820. X
  821. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  822. Xit is only released under the same conditions.
  823. X
  824. X    For bug reports, wishes, etc. send e-mail to
  825. X
  826. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  827. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  828. X
  829. X    For Physical mail:
  830. X
  831. X    Federico Heinz
  832. X    Beusselstr. 21
  833. X    1000 Berlin 21
  834. X
  835. X    Tel. (+49 30) 396 77 92
  836. X
  837. X*/
  838. X/**************************************************************************
  839. X
  840. X    Definition of the plotter's "hardware" functions.
  841. X
  842. X**************************************************************************/
  843. X
  844. X
  845. X/* Draws a dot at the curent position */
  846. X
  847. Xextern void drawDot();
  848. X
  849. X
  850. X/* Draws a line to the indicated point in User Space */
  851. X
  852. Xextern void drawLine();
  853. X
  854. X
  855. X
  856. X/* Positions the physical pen to the indicated point (User Space) */
  857. X
  858. Xextern void setCurrentPoint();
  859. X
  860. X
  861. X/* Draws an arc at maximum resolution */
  862. X
  863. Xextern void doHRArc();
  864. X
  865. X
  866. X/* Draw a horizontal tick */
  867. X
  868. Xextern void doYTick();
  869. X
  870. X
  871. X/* Draw a vertical tick */
  872. X
  873. Xextern void doXTick();
  874. X
  875. X
  876. X/* Set a new plotting window */
  877. X
  878. Xextern void setClip();
  879. X
  880. X
  881. X/* Set the plotting window again */
  882. X
  883. Xextern void correctClip();
  884. X
  885. X
  886. X/* Do the real ink-dropping if needed */
  887. X
  888. Xextern void stroke();
  889. X
  890. X
  891. X/* Set the pen's width */
  892. X
  893. Xextern void setPenWidth();
  894. X
  895. X
  896. X
  897. X/* Set the pen's color */
  898. X
  899. Xextern void setPenColor();
  900. X
  901. X
  902. X
  903. X/* Set the line pattern */
  904. X
  905. Xextern void setPattern();
  906. X
  907. X
  908. X
  909. X/* Shade a rectangle */
  910. X
  911. Xextern void doShadeRectangle();
  912. X
  913. X
  914. X
  915. X/* Shade a wedge */
  916. X
  917. Xextern void doShadeWedge();
  918. X
  919. X
  920. X
  921. X/* Do the machinery's startup work */
  922. X
  923. Xextern void initializeMachinery();
  924. X
  925. X
  926. X
  927. X/* Do anything that might be pending */
  928. X
  929. Xextern void shutdownMachinery();
  930. X
  931. X
  932. X/* Prelude file name */
  933. X
  934. Xextern char *PreludeFile;
  935. END_OF_FILE
  936. if test 2712 -ne `wc -c <'mchinery.h'`; then
  937.     echo shar: \"'mchinery.h'\" unpacked with wrong size!
  938. fi
  939. # end of 'mchinery.h'
  940. fi
  941. if test -f 'tick.c' -a "${1}" != "-c" ; then 
  942.   echo shar: Will not clobber existing file \"'tick.c'\"
  943. else
  944. echo shar: Extracting \"'tick.c'\" \(3067 characters\)
  945. sed "s/^X//" >'tick.c' <<'END_OF_FILE'
  946. X/*
  947. X        HPGL to PostScript converter
  948. X   Copyright (C) 1988 (and following) Federico Heinz
  949. X
  950. Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  951. XWARRANTY.  No author or distributor accepts responsibility to anyone
  952. Xfor the consequences of using it or for whether it serves any
  953. Xparticular purpose or works at all, unless he says so in writing.
  954. XRefer to the Free Software Foundation's General Public License for full details.
  955. X
  956. XEveryone is granted permission to copy, modify and redistribute yahp2ps,
  957. Xbut only under the conditions described in the GNU General Public
  958. XLicense.  A copy of this license is supposed to have been given to you
  959. Xalong with yahp2ps so you can know your rights and responsibilities.  It
  960. Xshould be in a file named COPYING.  Among other things, the copyright
  961. Xnotice and this notice must be preserved on all copies.
  962. X
  963. XIn other words, go ahead and share yahp2ps, but don't try to stop
  964. Xanyone else from sharing it farther.  Help stamp out software hoarding!
  965. X
  966. Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
  967. Xit is only released under the same conditions.
  968. X
  969. X    For bug reports, wishes, etc. send e-mail to
  970. X
  971. X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
  972. X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
  973. X
  974. X    For Physical mail:
  975. X
  976. X    Federico Heinz
  977. X    Beusselstr. 21
  978. X    1000 Berlin 21
  979. X
  980. X    Tel. (+49 30) 396 77 92
  981. X
  982. X*/
  983. X/***********************************************************************
  984. X
  985. X   Draw vertical or horizontal ticks.
  986. X
  987. X***********************************************************************/
  988. X
  989. X
  990. X#include "defs.h"
  991. X#include "dispatch.h"
  992. X#include "io.h"
  993. X#include "mchinery.h"
  994. X#include "penctrl.h"
  995. X#include "tick.h"
  996. X
  997. X
  998. X            /* Percentages of P2-P1 */
  999. Xstatic Number PositiveTick, NegativeTick;
  1000. X
  1001. X            /* Lengths of the corresponding ticks */
  1002. Xstatic Number PositiveXTick, NegativeXTick,
  1003. X              PositiveYTick, NegativeYTick;
  1004. X
  1005. X
  1006. X
  1007. X/*
  1008. X
  1009. X  Adjust tick parameters to a new environment.
  1010. X
  1011. X*/
  1012. X
  1013. Xvoid updateTicks()
  1014. X
  1015. X{ Number deltaX, deltaY;
  1016. X
  1017. X  if ((deltaX = PlotterP2[X] - PlotterP1[X]) < 0) deltaX = -deltaX;
  1018. X  if ((deltaY = PlotterP2[Y] - PlotterP1[Y]) < 0) deltaY = -deltaY;
  1019. X  PositiveXTick = mulNum(PositiveTick, deltaY / 100);
  1020. X  NegativeXTick = mulNum(NegativeTick, deltaY / 100);
  1021. X  PositiveYTick = mulNum(PositiveTick, deltaX / 100);
  1022. X  NegativeYTick = mulNum(NegativeTick, deltaX / 100);
  1023. X}
  1024. X
  1025. X
  1026. X
  1027. X/*
  1028. X
  1029. X  Reset tick parameters to default values.
  1030. X
  1031. X*/
  1032. X
  1033. Xvoid tickInit()
  1034. X
  1035. X{ PositiveTick = InitialTick;
  1036. X  NegativeTick = InitialTick;
  1037. X  updateTicks();
  1038. X}
  1039. X
  1040. X
  1041. X
  1042. X/*
  1043. X
  1044. X  Change the relative tick length.
  1045. X
  1046. X*/
  1047. X
  1048. XCommandImplementation setTickLength()
  1049. X
  1050. X{ if (isTerminator(LookAhead) || !getInteger(&PositiveTick))
  1051. X    tickInit();
  1052. X  else
  1053. X  { if (isTerminator(LookAhead) || !getInteger(&NegativeTick))
  1054. X      NegativeTick = Zero;
  1055. X    updateTicks();
  1056. X  }
  1057. X  endCommand();
  1058. X}
  1059. X
  1060. X
  1061. X
  1062. X/*
  1063. X
  1064. X  Do a X-axis tick.
  1065. X
  1066. X*/
  1067. X
  1068. XCommandImplementation xTick()
  1069. X
  1070. X{ doXTick(PositiveXTick, NegativeXTick);
  1071. X  endCommand();
  1072. X}
  1073. X
  1074. X
  1075. X
  1076. X/*
  1077. X
  1078. X  Do a Y-axis tick.
  1079. X
  1080. X*/
  1081. X
  1082. XCommandImplementation yTick()
  1083. X
  1084. X{ doYTick(PositiveYTick, NegativeYTick);
  1085. X  endCommand();
  1086. X}
  1087. X
  1088. X
  1089. X
  1090. X
  1091. END_OF_FILE
  1092. if test 3067 -ne `wc -c <'tick.c'`; then
  1093.     echo shar: \"'tick.c'\" unpacked with wrong size!
  1094. fi
  1095. # end of 'tick.c'
  1096. fi
  1097. echo shar: End of archive 2 \(of 6\).
  1098. cp /dev/null ark2isdone
  1099. MISSING=""
  1100. for I in 1 2 3 4 5 6 ; do
  1101.     if test ! -f ark${I}isdone ; then
  1102.     MISSING="${MISSING} ${I}"
  1103.     fi
  1104. done
  1105. if test "${MISSING}" = "" ; then
  1106.     echo You have unpacked all 6 archives.
  1107.     rm -f ark[1-9]isdone
  1108. else
  1109.     echo You still need to unpack the following archives:
  1110.     echo "        " ${MISSING}
  1111. fi
  1112. ##  End of shell archive.
  1113. exit 0
  1114.